#include "Logger.hpp"
#include "aip-cpp-sdk/speech.h"
namespace chatroom{
    class ASRClient{
        public:
            using ptr = std::shared_ptr<ASRClient>;
            ASRClient(std::string& app_id,std::string& api_key,std::string& secret_key):
            _client(app_id,api_key,secret_key){}
            std::string recogniztion(const std::string& specchdata,std::string& err)
            {
                Json::Value result = _client.recognize(specchdata, "pcm", 16000, aip::null);
                if(result["err_no"].asInt()!=0)
                {
                    Logger_ERROR("语音识别失败,{}",result["err_msg"].asString());
                    err = result["err_msg"].asString();
                    return std::string();
                }
                return result["result"][0].asString(); 
            }
        private:
            aip::Speech _client;
    };
}